package com.swgk.core.view.selection;

import android.content.Context;
import android.widget.TextView;


import com.swgk.core.BR;
import com.swgk.core.R;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

public class XChooseChildAdapter extends BaseRecycleAdapter<CommonPopEntity> {
    boolean isExpand;
    public XChooseChildAdapter(Context context, List<CommonPopEntity> datas, int tag, boolean isExpand) {
        super(context, tag, datas);
        this.isExpand = isExpand;

    }

    public void setExpand(boolean expand) {
        isExpand = expand;
    }

    @Override
    public int getItemCount() {
        if (getDatas().size() > 9) {
            if (isExpand) {
                return getDatas().size();
            } else {
                return 9;
            }
        }
        return super.getItemCount();
    }

    @Override
    public void convert(ItemViewHolder holder, final CommonPopEntity entity) {
        holder.setBinding(BR.viewModel, entity);
    }

    @Override
    public void onBindViewHolder(ItemViewHolder holder, int position) {
        super.onBindViewHolder(holder, position);
        TextView textView = holder.itemView.findViewById(R.id.tv_name);
        textView.setText(datas.get(position).getPickerViewText());
        if (holder.getItem().isSelected()) {
            textView.setBackgroundResource(R.drawable.shape_check_txt);
            textView.setTextColor(holder.itemView.getContext().getResources().getColor(R.color.color_main));
        } else {
            textView.setBackgroundResource(R.drawable.shape_uncheck_txt);
            textView.setTextColor(holder.itemView.getContext().getResources().getColor(R.color.color_tab_two));
        }
    }

}
